﻿using System.Collections;
using CSharpPro._10_16;

namespace CSharpPro._1030;

public class UserServiceImpl:UserService
{
    private Dictionary<int, string> _data = new Dictionary<int, string>();

    public void Add(string item)
    {
        int id = _data.Count + 1;
        _data.Add(id, item);
        Console.WriteLine($"添加成功：ID={id}, 内容={item}");
    }

    public void Delete(int id)
    {
        if (_data.Remove(id))
        {
            Console.WriteLine($"删除成功：ID={id}");
        }
        else
        {
            Console.WriteLine($"删除失败：未找到ID={id}");
        }
    }

    public void Update(int id, string newItem)
    {
        if (_data.ContainsKey(id))
        {
            _data[id] = newItem;
            Console.WriteLine($"更新成功：ID={id}, 新内容={newItem}");
        }
        else
        {
            Console.WriteLine($"更新失败：未找到ID={id}");
        }
    }

    public string Get(int id)
    {
        if (_data.TryGetValue(id, out string result))
        {
            Console.WriteLine($"查询成功：ID={id}, 内容={result}");
            return result;
        }
        Console.WriteLine($"查询失败：未找到ID={id}");
        return null;
    }
}